package com.yonghui;

import lombok.extern.slf4j.Slf4j;

import java.lang.ref.PhantomReference;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;

@Slf4j
public class PhantomReferenceTest {

    public static void main(String[] args) {
        Student student=new Student("张三",22);
        ReferenceQueue<Student> queue=new ReferenceQueue<>();
        PhantomReference pr=new PhantomReference(student,queue);

        //不可获取虚引用中的对象
        log.info("打印对象{}",pr.get());
        student=null;
        System.gc();
        Reference<? extends Student> poll = queue.poll();
        System.out.println(poll.toString());
    }
}
